﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CMS.Domain.Services
{
    public class EnableService
    {
        public CPPEI.ServiceResult EnableArticle(Guid id)
        {
            using (CMSDbContext dbContext = new CMSDbContext())
            {
                EntityRepository<Entities.EArticle> rep = new EntityRepository<Entities.EArticle>(dbContext);

                Entities.EArticle article = rep.Get(p => p.Id == id);
                if (article == null)
                {
                    return new CPPEI.ServiceResult(0);
                }
                article.IsEnabled = true;
                rep.Update(article);

                try
                {
                    dbContext.SaveChanges();
                    return new CPPEI.ServiceResult();
                }
                catch (Exception ex)
                {
                    return new CPPEI.ServiceResult(0);
                }
            }
        }
    }
}
